﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

///This class will handle outputting various data for debuggin purposes.
///They'll draw directly to the screen and scroll with the camera, or the player.

namespace MyImaginaryFriends_Redux.Screens
{
    class Debug
    {
        #region Variable(s)
        SpriteFont DebugFont;

        bool b_isDebug_Level = false;
        bool b_isDebug_Player = false;
        bool b_isDebug_Friend = false;
        bool b_isDebug_Enemy = false;
        bool b_isDebug_Camera = false;
        bool b_isDebug_Event = false;
        bool b_isDebug_HUD = false;

        #endregion

        public Debug()
        {
            //Buildin' a Sentreh
            
        }

        public void LoadContent(ContentManager content)
        {
            DebugFont = content.Load<SpriteFont>("MenuContent//Arial");
        }

        public void Update(InputHandler input)
        {
            if (input.GetKBStateSingle(Keys.D0))
            {
                //level debug values
                if (!b_isDebug_Level)
                {
                    b_isDebug_Level = true;
                    b_isDebug_Player = false;
                    b_isDebug_Friend = false;
                    b_isDebug_Enemy = false;
                    b_isDebug_Camera = false;
                    b_isDebug_Event = false;
                    b_isDebug_HUD = false;
                }
                else
                    b_isDebug_Level = false;
            }
            if (input.GetKBStateSingle(Keys.D1))
            {
                //player debug values
                if (!b_isDebug_Player)
                {
                    b_isDebug_Level = false;
                    b_isDebug_Player = true;
                    b_isDebug_Friend = false;
                    b_isDebug_Enemy = false;
                    b_isDebug_Camera = false;
                    b_isDebug_Event = false;
                    b_isDebug_HUD = false;
                }
                else
                    b_isDebug_Player = false;
            }
            if (input.GetKBStateSingle(Keys.D2))
            {
                //friend debug values
                if (!b_isDebug_Friend)
                {
                    b_isDebug_Level = false;
                    b_isDebug_Player = false;
                    b_isDebug_Friend = true;
                    b_isDebug_Enemy = false;
                    b_isDebug_Camera = false;
                    b_isDebug_Event = false;
                    b_isDebug_HUD = false;
                }
                else
                    b_isDebug_Friend = false;
            }
            if (input.GetKBStateSingle(Keys.D3))
            {
                //enemy debug values//gotta figure this shit out.
                if (!b_isDebug_Enemy)
                    b_isDebug_Enemy = true;
                else 
                    b_isDebug_Enemy = false;
            }
            if (input.GetKBStateSingle(Keys.D4))
            {
                //camera debug values
                if (!b_isDebug_Camera)
                {
                    b_isDebug_Level = false;
                    b_isDebug_Player = false;
                    b_isDebug_Friend = false;
                    b_isDebug_Enemy = false;
                    b_isDebug_Camera = true;
                    b_isDebug_Event = false;
                    b_isDebug_HUD = false;
                }
                else
                    b_isDebug_Camera = false;
            }
            if (input.GetKBStateSingle(Keys.D5))
            {
                //whatever else we can think of... perhaps Event Debugging.
                if (!b_isDebug_Event)
                {
                    b_isDebug_Level = false;
                    b_isDebug_Player = false;
                    b_isDebug_Friend = false;
                    b_isDebug_Enemy = false;
                    b_isDebug_Camera = false;
                    b_isDebug_Event = true;
                    b_isDebug_HUD = false;
                }
                else
                    b_isDebug_Event = false;
            }
            if (input.GetKBStateSingle(Keys.D6))
            {
                //maybe HUD debugging
                if (!b_isDebug_HUD)
                {
                    b_isDebug_Level = false;
                    b_isDebug_Player = false;
                    b_isDebug_Friend = false;
                    b_isDebug_Enemy = false;
                    b_isDebug_Camera = false;
                    b_isDebug_Event = false;
                    b_isDebug_HUD = true;
                }
                else
                    b_isDebug_HUD = false;
            }
            if (input.GetKBStateSingle(Keys.D7))
            {
            }
            if (input.GetKBStateSingle(Keys.D8))
            {
            }
            if (input.GetKBStateSingle(Keys.D9))
            {
            }
        }

        public void Draw(SpriteBatch spriteBatch, GamePlayScreen_Classes.PlayerEntity player,
                                                  GamePlayScreen_Classes.FriendEntity friend,
                                                  /*GamePlayScreen_Classes.EnemyEntity enemy,*/
                                                  GamePlayScreen_Classes.Camera camera,
                                                  GameplayScreen level,
                                                  ScriptedEvent _event)
        {
            if (b_isDebug_Level)
            {
                spriteBatch.DrawString(DebugFont, "LevelDebug------------------------- ", new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Current Region: " + level.GetCurrentRegion(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 20), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Previous Region: " + level.GetPreviousRegion(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 40), Color.White * 0.5f);

            }
            if (b_isDebug_Player)
            {
                spriteBatch.DrawString(DebugFont, "PlayerDebug------------------------- ", new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Position: " + player.v2_Position, new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 20), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Velocity: " + player.v2_Velocity, new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 40), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Collision: " + friend.GetTTFCollision().ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 60), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Bounds: " + player.BoundingRectangle.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 80), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "IsReqBLockRm2_To_A " + player.b_RequestActivate_GateTrigger_BlockRoom2ToRoomA.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 100), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "IsrmAGateActive " + player.b_isRoomAGateActive.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 120), Color.White * 0.5f);
                
               
                

                //place whatever else the fuck you want to see in here, this class will have FULL GODDAMN ACCESS to ALL VALUES
            }
            if (b_isDebug_Friend)
            {
                spriteBatch.DrawString(DebugFont, "FriendDebug------------------------- ", new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Position: " + friend.v2_Position, new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 20), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Velocity: " + friend.v2_Velocity, new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 40), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Collision: " + friend.GetTTFCollision().ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 60), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "RactivateRoomBDoorTrigger: " + friend.b_RequestActivate_RoomBDoorTrigger.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 80), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "local vectors: " + friend.rec_localBounds.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 100), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Collision vectors: " + friend.BoundingRectangle.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 120), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Friend Summoned: " + friend.b_IsSummoned.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 140), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Summon Timer: " + player.f_SummonTimer.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 160), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Is Healing: " + friend.b_isHealing.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 180), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Is friend in time out?: " + player.b_friendTimeOut.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 200), Color.White * 0.5f);
            }
            if (b_isDebug_Camera)
            {
                spriteBatch.DrawString(DebugFont, "CameraDebug------------------------- ", new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Position: " + camera.v2Position, new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 20), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "LeftM: " + camera.GetMarginLeft(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 40), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "RightM: " + camera.GetMarginRight(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 60), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "TopM: " + camera.GetMarginTop(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 80), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "BottomM: " + camera.GetMarginBottom(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 100), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "MWidth: " + camera.GetMarginWidth(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 120), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "MHeight: " + camera.GetMarginHeight(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 140), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "MaxPos: " + camera.GetMaxCameraPosition(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 160), Color.White * 0.5f);
            }

            if (b_isDebug_Event)
            {
                spriteBatch.DrawString(DebugFont, "Event Debug------------------------- ", new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y), Color.White * 0.5f);
                spriteBatch.DrawString(DebugFont, "Is Event Active: " + _event.b_IsEventActive.ToString(), new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y + 20), Color.White * 0.5f);
                
                
            }

            

        }
    }
}
